<?php
namespace app\system\controller;

use app\common\model\UserGroupModel;
use think\Request;
use think\Session;

class BaseController extends \think\Controller
{
    private $uid;
    /**
     * 初始化
     * BaseController constructor.
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        parent::__construct($request);
        $des = is_login($this->getUtype());
        if ($des === false || $this->getUtype()!=$des['utype']) {
            $this->error('请登录后再操作！',url('Public/Login'));
        }else{
            $this->uid = $des['uid'];
            $this->assign('uid',$this->uid);
        }
    }

    /**
     * 获取用户类型
     * @return string
     */
    public function getUtype()
    {
        return 'system';
    }

    /**
     * 获取用户UID
     * @return bool|mixed
     */
    public function getUid()
    {
        return $this->uid;
    }

    /**
     * 获取权限组ID
     */
    public function getGroupIds(){
        if(!Session::has('group_ids')){
            $userGroupModel = new UserGroupModel();
            $groupIds = $userGroupModel->getGroupIds($this->getUid(),$this->getUtype());
            Session::set('group_ids',$groupIds);
            return $groupIds;
        }
        return Session::get('group_ids');
    }

}